<template>
	<view class="control" :style="{paddingBottom:selectionArr.length > 1 ?'400rpx' : '200rpx'}">
		<view class="time-list">
			<view @click="selectDay(item,index)" :class="{'active':dayActive == index}" class="time-item"
				v-for="(item,index) in dataList" :key="index">
				<view class="day">{{item.weeks}}</view>
				<view class="date">{{item.mouth}}/{{item.day}}</view>
			</view>
		</view>
		<u-notice-bar fontSize="12" direction="column" :text="['节假日期间预定场地不得退订，若要退订请联系客服']"></u-notice-bar>

		<!-- 场地预定表格 -->
		<view class="table-box">
			<view class="tr colum vv" id='vv' ref="innerbox">
				<view class="td date" v-for="(item,index) in fieldlist" :key="index">
					<view style="font-weight: bold;" class="date-1" v-if="index !== 0">{{item.start_time}}
					</view>
					<view style="font-weight: bold;" v-if="index !== 0">{{item.end_time}}</view>
				</view>
			</view>

			<scroll-view class="table" scroll-x :style="{width:else_width }" ref="table">
				<view class="tr">
					<view class="td name" style="background-color:skyblue;" v-for="(item,index) in fieldNoList">
						<view>{{item.date}}</view>
						<view>{{item.week}}</view>
					</view>
				</view>
				<view class="tr" v-for="(line,index) in fieldlist" :key="index">
					<!-- <view :class="{'select-td':selectList.includes(indexs)}" class="td" @click="selectData(colum,indexs)" -->
					<view class="td" v-for="(colum,indexs) in line.course" :key="indexs">
						<!-- 内容 -->
						<view class="price-box">
							<view class="price">
								<view class="" style="width: 150rpx; height: 150rpx;"
									:style="{backgroundColor:colum.color?colum.color:'#59A0FFFF'}"><!-- #59A0FFFF -->
									<text>{{colum.name}}</text>
								</view>
							</view>
							<!-- <view class="price-2">5/20</view> -->
						</view>

					</view>
				</view>
			</scroll-view>
		</view>

		<view class="footer">
			<scroll-view class="footer-3" scroll-x v-if="selectionArr.length > 0">
				<view class="flex-align">
					<view class="item" v-for="(im,indexx) in selectionArr" :key="indexx">
						<view class="icon" @click="removeData(im,indexx)">
							<u-icon name="close-circle-fill" color="#000000" size="17"></u-icon>
						</view>
						<view class="item-time">{{im.month_day}}({{im.week}})</view>
						<view class="item-con">
							<view class="item-con1">羽毛球-{{im.num}}</view>
							<view class="item-con1">{{im.dateTimes}}</view>
						</view>
					</view>
				</view>

			</scroll-view>


		</view>
		<!-- <template>
		  <view ref="view" class="measure"></view>
		  <view class="my-component" :style="{width: width + 'px'}">My Component</view>
		</template> -->
		<view class="JWL_Video_Item_3" ref="viewref">
			<view id="JWLvideo-container"></view>
		</view>
	</view>
</template>

<script>
	const subscribe = require("@/api/subscribe/index.js");
	export default {
		data() {
			return {
				maxbooknum: 2, // 一次订多少个场地
				data_time: true,
				t_width: '',
				timne_s: '',
				dayActive: 0,
				dataList: [], //日期
				selectList: [],
				fieldNoList: ["1号场", "2号场", "3号场", "4号场", "5号场", "6号场", "7号场", "8号场"],
				fieldlist: [{
						id: "14",
						starttime: "",
						endtime: ""
					},
					{
						id: "37",
						starttime: "08:00",
						endtime: "10:00",
						fieldlist_s: [{
								timeprice: "60.00",
							},
							{
								timeprice: "80.00",
							},
							{
								timeprice: "",
							},
							{
								timeprice: "100.00",
							},
							{
								timeprice: "80.00",
							},
							{
								timeprice: "",
							},
							{
								timeprice: "100.00",
							},
							{
								timeprice: "10.00",
							},
							{
								timeprice: "",
							}
						]
					},
					{
						id: "13",
						starttime: "10:00",
						endtime: "17:00",
						fieldlist_s: [{
								timeprice: "30.00",
							},
							{
								timeprice: "",
							},
							{
								timeprice: "30.00",
							},
							{
								timeprice: "90.00",
							},
							{
								timeprice: "80.00",
							},
							{
								timeprice: "",
							}
						]
					},
					{
						id: "28",
						starttime: "17:00",
						endtime: "22:00",
						fieldlist_s: [{
								timeprice: "40.00",
							},
							{
								timeprice: "80.00",
							},
							{
								timeprice: "",
							},
							{
								timeprice: "100.00",
							},
							{
								timeprice: "10.00",
							},
							{
								timeprice: "",
							},
						]
					}
				],
				selectionArr: [], // 选中的场地
				current_year_month: '', //年月日
				current_month_day: '', //几月几号
				today: '', //日期
				line_time: '', //时间戳
				weeks_data: '', //星期几
				money: 0, //总计价格,
				else_width: '',
				width: 0
			}
		},
		// mounted() {
		//     this.width = this.$refs.view.$el.offsetWidth;
		//   },

		onReady() {
			let getWindowInfo = uni.getWindowInfo();
			let windowWidth = getWindowInfo.windowWidth
			let obj = uni.createSelectorQuery().select('.vv')
			obj.boundingClientRect(function(data) {
				this.t_width = data.width;
				let else_width = windowWidth - data.width;
				this.else_width = else_width
			}).exec()
		},
		onLoad(options) {
			var _this = this
			_this.getCurrentMonthDay()
			this.course()
			setTimeout(() => { // 设置setTimeout延迟调用
				this.getVideo();
			}, 6000)
		},
		methods: {
			getVideo() {
				let width = this.$refs.viewref.$el.offsetWidth;
				let height = this.$refs.viewref.$el.offsetHeight;
			},
			async course() {
				let that = this;
				let data = {};
				let result = await subscribe.course(data);
				if (result.code == 1) {
					this.fieldNoList = []
					this.fieldNoList = result.data.data.date
					this.fieldlist = []
					this.fieldlist = result.data.data.courses;
					this.fieldlist.unshift({
						id: "14",
						time: "",
					})
					// result.data.data.course.forEach((item,index)=>{
					// 	this.fieldlist.starttime=item.time
					// 	this.fieldlist.key=index
					// })
				}
			},
			getRefs() {
				let that = this
				return new Promise((resolve, reject) => {
					resolve(that.$refs)
				})
			},
			// 获取今天当前日期
			getCurrentMonthDay() {
				var _this = this
				var now = new Date()
				var y = now.getFullYear()
				var m = now.getMonth() + 1
				var d = now.getDate()
				if (m < 10) {
					m = '0' + m
				}
				if (d < 10) {
					d = '0' + d
				}
				var date = m + '/' + d
				var date_s = m + '-' + d
				_this.current_month_day = date_s
				_this.current_year_month = y + '-' + m + '-' + d
				_this.today = date
				_this.weeks_data = '今天'
				console.log(_this.current_month_day)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.control {
		width: 100%;
		background-color: #F7F7F7;
		min-height: 100vh;
		position: relative;
		padding-bottom: 200rpx;

		.time-list {
			padding: 8rpx 30rpx;
			display: flex;
			align-items: center;

			.time-item {
				flex: 1;
				padding: 15rpx 0;
				border-radius: 10rpx;
				color: #333333;
				display: flex;
				flex-direction: column;
				align-items: center;

				.day {
					font-size: 22rpx;
					font-weight: bold;
				}

				.date {
					font-family: PingFang SC;
					// font-weight: bold;
					font-size: 19rpx;
					margin-top: 10rpx;
				}
			}

			.active {
				background-color: #FF8E05;
				color: white;
			}
		}

		.table-box {
			display: flex;
			background-color: white;
		}

		.colum {
			display: block !important;
		}

		.tr {
			display: flex;
			margin-top: 4rpx;

			.td {
				width: 150rpx;
				height: 150rpx;
				margin-right: 8rpx;
				margin-top: 4rpx;
				flex-shrink: 0;
				background: #EAEAEA;
				border-radius: 8px;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				.price-box {
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;

					.price {
						font-size: 20rpx;
						font-weight: 400;
						color: #FFFFFF;
						line-height: 150rpx;
						text-align: center;

						text {
							font-size: 20rpx;
						}
					}

					.price-2 {
						font-size: 20rpx;
						font-weight: 400;
						color: #FFFFFF;
					}
				}
			}

			.date {
				color: #333333;
				font-size: 20rpx;
				border-radius: 0 !important;
				background-color: white;
				margin-top: 11rpx;

				.date-1 {
					position: relative;
					padding-bottom: 10rpx;

					// &:after {
					// 	content: '-';
					// 	display: block;
					// 	position: absolute;
					// 	bottom: -5rpx;
					// 	left: 0;
					// 	right: 0;
					// 	width: fit-content;
					// 	margin: auto;
					// }
				}

				&:first-of-type {
					margin: 0;
				}
			}

			.name {
				border-radius: 0 !important;
				background-color: white;
				color: #303030;
				font-size: 22rpx;
				// margin-top: 4rpx;
			}

			.select-td {
				background-color: #df42d9;
			}

			.select-grey {
				background: #EAEAEA;
			}

			.select-blue {
				background: #59A0FFFF;
			}
		}

		.footer {
			padding: 30rpx 30rpx;
			background-color: white;
			position: fixed;
			bottom: 0;
			width: 100%;
			left: 0;

			.footer-1 {
				.info-1 {
					font-size: 28rpx;
					color: #333333;
				}

				.info-2 {
					font-size: 28rpx;
					font-weight: 500;
					color: #FF4105;

					text {
						font-weight: 700;
						font-size: 40rpx;
					}
				}

				.btn {
					width: 35%;
					color: white;
					padding: 15rpx 0;
					font-size: 28rpx;
					text-align: center;
					border-radius: 30px;
					background-color: #dcdcdc;
				}

				.btn_n {
					width: 35%;
					color: white;
					padding: 15rpx 0;
					font-size: 28rpx;
					text-align: center;
					border-radius: 30px;
					background-color: #59A0FFFF;
				}
			}

			.footer-2 {
				margin-bottom: 15rpx;

				.info-1 {
					font-size: 22rpx;
					font-weight: bold;
					color: #008CFF;

					image {
						width: 30rpx;
						height: 30rpx;
						margin-right: 8rpx;
					}
				}

				.info-2 {
					flex: 1;
					margin-left: 60rpx;

					.tag-item {
						font-size: 24rpx;
						font-weight: bold;
						color: #333333;

						.color {
							width: 28rpx;
							height: 28rpx;
							background: #EAEAEA;
							border-radius: 4rpx;
							margin-right: 15rpx;
						}

						.color2 {
							background-color: #6373e8;
						}

						.color3 {
							background-color: #a6ccff;
						}

						.color4 {
							background-color: #df42d9;
						}
					}
				}
			}

			.footer-3 {
				display: flex;
				margin-bottom: 30rpx;

				.item {
					background: #F3F3F3;
					border-radius: 5px;
					flex-shrink: 0;
					width: fit-content;
					margin-top: 20rpx;
					margin-right: 40rpx;
					position: relative;

					.icon {
						position: absolute;
						top: -14rpx;
						right: -14rpx;
					}

					.item-time {
						font-size: 22rpx;
						background: #DF42D9;
						color: #FFFFFF;
						text-align: center;
						padding: 5rpx 0;
						border-radius: 5px 5px 0 0;
					}

					.item-con {
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;
						padding: 16rpx;
						font-size: 22rpx;
						font-weight: bold;

						.item-con1 {

							color: #333333;
							margin-bottom: 15rpx;
						}

						.item-con2 {
							color: #DF42D9;
						}
					}
				}
			}
		}
	}
</style>